const path = require('path')
const webpack = require('webpack')
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

function resolve (dir) {
  return path.join(__dirname, dir)
}

const port = process.env.port || process.env.npm_config_port || 8860 // dev port

module.exports = {
  lintOnSave: false,
  productionSourceMap: false,
  configureWebpack: {
    plugins: [
      new NodePolyfillPlugin(),
      // Ignore all locale files of moment.js
      new webpack.IgnorePlugin({
        resourceRegExp: /^\.\/locale$/,
        contextRegExp: /moment$/
      })
    ],
    resolve: {
      fallback: {
        fs: false,
        crypto: require.resolve("crypto-browserify")
      }
    }
  },

  chainWebpack: (config) => {
    config.plugins.delete('prefetch')
    config.plugins.delete('preload')
    config.resolve.alias
      .set('@$', resolve('src'))
      .set('@api', resolve('src/api'))
      .set('@assets', resolve('src/assets'))
      .set('@comp', resolve('src/components'))
      .set('@views', resolve('src/views'))
      .set('@layout', resolve('src/layout'))
      .set('@static', resolve('src/static'))
      .set('@config', resolve('config'))
  },

  css: {
    loaderOptions: {
      less: {
        modifyVars: {
          /* less 变量覆盖，用于自定义 ant design 主题 */
          'primary-color': '#0087E1',
          'link-color': '#0087E1',
          // 'success-color': '#43D8D2',
          // 'warning-color': '#F75353',
          // 'error-color': '#FA6993',
          'font-size-base': '14px',
          'heading-color': '#0F121B',
          'text-color': '#0F121B',
          'text-color-secondary': '#8193B1',
          'disabled-color': '#ABB8CE',
          'border-radius-base': '2px',
          'border-color-base': '#E5EBF3',
          'box-shadow-base': '0 3px 7px rgba(25, 55, 92, 0.06)'
        },
        javascriptEnabled: true
      }
    }
  },
  devServer: {
    port: port,
    open: false,
    host: '0.0.0.0',
    client: {
      overlay: false
    },
    proxy: {
      '/api': {
        // target: 'https://testepayment.primelifescience.com.cn/api/',
        target: 'https://epayment-dev.primelifescience.com.cn/api/',
        // target: 'http://192.168.1.81:8091/epayment/', // 华国本地
        // target: 'http://192.168.1.97:8081/epayment', // 贤财本地
        // target: 'http://192.168.1.57:8081/epayment', // 鹏辉本地
        // target: 'http://192.168.1.86:8091/epayment', // 梦其本地
        // target: 'http://192.168.1.105:8091/epayment', // 其豪本地
        // target: 'https://epayment-uat.primelifescience.com.cn/api/',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    }
  },
  lintOnSave: false,
  // babel-loader no-ignore node_modules/*
  transpileDependencies: []
}
